<?php 
include(dirname(__FILE__)."/inc/taobaoCom.php");
include(dirname(__FILE__)."/inc/template.class.php");
$class = new taobaoCom();
$templateRoot = dirname(__FILE__)."/templates/";
$cats = $class->getSonCats("0");
$provinces = $class->showProvinces();
if (isset($_GET))
{
	$catID = filter_input(INPUT_GET,"catID",FILTER_VALIDATE_INT);
	$keyWord = filter_input(INPUT_GET,"q");
	$startPrice = filter_input(INPUT_GET,"sp");
	$endPrice = filter_input(INPUT_GET,"ep");
	$orderBy = filter_input(INPUT_GET,"by");
	$order = filter_input(INPUT_GET,"o");
	$areaID = filter_input(INPUT_GET,'areaID');
	$orderStr='';
	if ($orderBy && $order)
	{
		$orderStr = $orderBy.":".$order;
	}
	$page = filter_input(INPUT_GET,'p');
	if(!$page)
	{
		$page = 1;
	}
	$pageSize = 40;
	$seaResult = $class->seaTaobaoPruduct($keyWord,$catID,$startPrice,$endPrice,$page,$pageSize,$orderStr,$areaID);
	$seaNum = $seaResult['totalResults'];
	$totalPage = ceil($seaNum/$pageSize);
	$items = $seaResult['itemsearchs'][0]['item_list'];
	$catResult = $seaResult['itemsearchs'][0]['category_list'];
	$pageStr = $class->numofpage($page,$totalPage);
}
$tpl = new Template($templateRoot);
$cats = $class->getCats("0");
$tpl->assign("cats",$cats);
$tpl->assign("items",$items);
$tpl->assign("seaNum",$seaNum);
$tpl->assign("totalPage",$totalPage);
$tpl->assign("catResult",$catResult);
$tpl->assign("pageStr",$pageStr);
$tpl->assign("keyWord",$keyWord);
$tpl->assign("seaCat",$catID);
$tpl->assign("provinces",$provinces);
$tpl->assign("seaAreaId",$areaID);
$tpl->display("search.tpl.php");
?>
